package restful

import (
	"context"
	"github.com/go-kit/kit/endpoint"
	"github.com/mitchellh/mapstructure"
	"github.com/shinedone/srv-server/internal/modules/enterprise/srv"
)

type Handlers struct {
	EnterpriseSrv *srv.EnterpriseSrv `inject:""`
}

func (h *Handlers) GetById() endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(string)
		res, err := h.EnterpriseSrv.GetByEnterpriseId(ctx, req)
		if err != nil {
			return nil, err
		}
		return res, nil
	}
}

func (h *Handlers) QueryEnterprise() endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(*QueryEnterpriseReq)
		queryBo := &srv.ListQueryBo{}
		err = mapstructure.Decode(req, queryBo)
		if err != nil {
			return nil, err
		}
		return h.EnterpriseSrv.List(ctx, queryBo)
	}
}
